﻿#include "mreditdialog.h"
#include "ui_mreditdialog.h"

#include <QDate>
#include <QDebug>

int MReditDialog::ID;
MReditDialog::MReditDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MReditDialog)
{
    ui->setupUi(this);
    ui->frame->resize(this->geometry().width(), ui->frame->height());
    ui->status->setText("修改信息状态：");
    connect(ui->cancelbtn,SIGNAL(clicked(bool)),this,SLOT(close()));
}

MReditDialog::~MReditDialog()
{delete ui;}

void MReditDialog::receiveData(QStringList fan)
{//获取传递过来的数据
ID=fan.at(0).toInt();
QDate date=QDate::fromString(fan.at(1),"yyyy-MM-dd");
ui->dateEdit->setDate(date);
ui->unit->setText(fan.at(2));
ui->envelope->setText(fan.at(3));
ui->copies->setText(fan.at(4));
ui->content->setText(fan.at(5));
}

void MReditDialog::on_ackbtn_clicked()
{
    if(ui->content->text().isEmpty()||ui->copies->text().isEmpty()||ui->unit->text().isEmpty()){
         ui->status->setText("修改信息状态:接收日期，接收单位，接收内容，份数不能为空!");
    }else{

        QSqlQuery query;
        query.prepare("update ZZB.MaterialReceive set ReceiveDate=?,OriginalUnit=?,OriginalEnvelope=?,Copies=?,MaterialContent=? where ReceiveID = ?");
        query.addBindValue(ui->dateEdit->text());
        query.addBindValue(ui->unit->text());
        query.addBindValue(ui->envelope->text());
        query.addBindValue(ui->copies->text());
        query.addBindValue(ui->content->text());
        query.addBindValue(ID);
        bool ok=query.exec();
        if(ok)
        {ui->status->setText("修改信息状态:修改成功");
                this->close();}
        else{ui->status->setText("修改信息状态:修改失败");}}
}
